package example.service;

import java.io.IOException;
import java.util.Map;

import example.oauth.OAuthAccessor;
import example.oauth.OAuthConsumer;
import example.oauth.OAuthServiceProvider;
import example.oauth.client.OAuthClient;

public class TokenService {
	public static final String REQUEST_TOKEN_URL = "https://open.t.qq.com/cgi-bin/request_token";
	public static final String USER_AUTHORIZATION_URL = "https://open.t.qq.com/cgi-bin/authorize";
	public static final String ACCESS_TOKENURL = "https://open.t.qq.com/cgi-bin/access_token";
	public static final String OAUTH_CONSUMER_KEY = "1c7c3e03d1b341ffa46df94dcc77926a";
	public static final String OAUTH_CONSUMER_SECRET = "c363a0a54fa42fc92ef28330a9ffaa14";
	public static final OAuthConsumer consumer;
	public final static OAuthServiceProvider serviceProvider;
	public final static OAuthAccessor accessor;
	static{
		serviceProvider = new OAuthServiceProvider(REQUEST_TOKEN_URL,USER_AUTHORIZATION_URL,ACCESS_TOKENURL);
		consumer = new OAuthConsumer("android://OAuthAccessActivity", OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, serviceProvider);
		accessor = new OAuthAccessor(consumer);
	}
	//private OAuthClient client = null;
	
	public TokenService(){
		//client = new OAuthClient();
	}
	
	public static Map<String,String> getRequestToken(){
		OAuthClient client = new OAuthClient();
		Map<String,String> params = null;
		//String requestToken = null;
		try {
			params = client.getRequestToken(accessor, "GET");
		} catch (Exception e){
			e.printStackTrace();
		}
		return params;
	}
	public static String getAccessToken(String requestToken,String tokenSecret,String verifier){
		OAuthClient client = new OAuthClient();
		String accessToken = null;
		try {
			accessToken = client.getAccessToken(accessor,requestToken,tokenSecret,verifier,"GET");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return accessToken;
	}
	

}
